package com.zoe.spring.controller;

import cn.hutool.core.util.StrUtil;
import com.zoe.spring.controller.frontend.MainPageInfoController;
import com.zoe.spring.controller.superadmin.HeadLineOperationController;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Zoe.Zhang
 * @date 2022/01/12
 * @description
 */
@WebServlet("/")
public class DispatchServlet extends HttpServlet {
    private static final long serialVersionUID = 8081114369368582673L;

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("requestPath====" + req.getServletPath());
        System.out.println("requestMethod====" + req.getMethod());
        if (StrUtil.equals(req.getServletPath(), "/frontend/getmainpageinfo") && StrUtil.equals(req.getMethod(), "GET")) {
            new MainPageInfoController().getMainPageInfo(req, resp);
        } else if (StrUtil.equals(req.getServletPath(), "/superadmin/addheadline") && StrUtil.equals(req.getMethod(), "POST")) {
            new HeadLineOperationController().addHeadLine(req, resp);
        }
    }
}
